import request from '@/utils/request'
import { deepClone } from '@/utils'
const { asyncRoutes, constantRoutes } = require('../router')

const routes = deepClone([...constantRoutes, ...asyncRoutes])

export function getRoutes() {
return {
  code: 20000,
  data: routes
}
}

export function fetchRoleList() {
  const roles = [
    {
      key: '经费科目管理员',
      name: '经费科目管理员',
      description: 'Super Administrator. Have access to view all pages.',
      routes: routes
    },
    {
      key: '院领导',
      name: '院领导',
      description: 'Normal Editor. Can see all pages except permission page',
      routes: routes.filter(i => i.path !== '/permission')// just a mock
    },
    {
      key: 'visitor',
      name: 'visitor',
      description: 'Just a visitor. Can only see the home page and the document page',
      routes: [{
        path: '',
        redirect: 'dashboard',
        children: [
          {
            path: 'dashboard',
            name: '主页',
            meta: { title: '主页', icon: 'dashboard' }
          }
        ]
      }]
    }
  ]
  return {
    code: 20000,
    data: roles
  }
}

export function fetchAllRoles(id) {
  return request({
    url: `/roles`,
    method: 'get'
  })
}

export function fetchRoleById(id) {
  return request({
    url: `/roles/${id}`,
    method: 'get'
  })
}

export function createRole(data) {
  return request({
    url: '/roles',
    method: 'post',
    data
  })
}

export function updateRole(id, data) {
  return request({
    url: `/roles/${id}`,
    method: 'put',
    data
  })
}

export function deleteRole(id) {
    return request({
      url: `/roles/${id}`,
      method: 'delete'
    })
}
